package com.taobao.txc.a.b;

import com.taobao.txc.common.c.F;
import com.taobao.txc.common.config.o;
import com.taobao.txc.common.d;
import com.taobao.txc.common.util.d.a;
import io.netty.buffer.ByteBuf;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import org.apache.commons.lang.StringUtils;

public class c
  extends F
  implements Serializable
{
  private String b;
  private String c = a.a();
  private String d;
  private String e = "";
  private String f;
  private int g;
  private String h;
  public ByteBuffer a = ByteBuffer.allocate(2097152);
  
  public c() {}
  
  public c(String paramString1, String paramString2, String paramString3, int paramInt)
  {
    this.b = paramString1;
    this.d = paramString2;
    this.f = paramString3;
    this.g = paramInt;
    if ((paramString3 != null) && (!paramString3.isEmpty()))
    {
      this.e = String.format("%s=%s\n", new Object[] { "vgroup", paramString3 });
      this.h = d.a();
      if (!StringUtils.isEmpty(this.h)) {
        this.e = String.format("%s\n%s=%s\n", new Object[] { this.e, "ip", this.h });
      }
    }
  }
  
  public void a(String paramString)
  {
    this.b = paramString;
  }
  
  public void b(String paramString)
  {
    this.c = paramString;
  }
  
  public void c(String paramString)
  {
    this.d = paramString;
  }
  
  public short b_()
  {
    return 101;
  }
  
  public byte[] c()
  {
    if (this.b != null)
    {
      arrayOfByte = this.b.getBytes(j);
      this.a.putShort((short)arrayOfByte.length);
      if (arrayOfByte.length > 0) {
        this.a.put(arrayOfByte);
      }
    }
    else
    {
      this.a.putShort((short)0);
    }
    if (this.c != null)
    {
      arrayOfByte = this.c.getBytes(j);
      this.a.putShort((short)arrayOfByte.length);
      if (arrayOfByte.length > 0) {
        this.a.put(arrayOfByte);
      }
    }
    else
    {
      this.a.putShort((short)0);
    }
    if (this.d != null)
    {
      arrayOfByte = this.d.getBytes(j);
      this.a.putInt(arrayOfByte.length);
      if (arrayOfByte.length > 0) {
        this.a.put(arrayOfByte);
      }
    }
    else
    {
      this.a.putInt(0);
    }
    if ((this.e != null) && (!this.e.isEmpty()))
    {
      arrayOfByte = this.e.getBytes(j);
      this.a.putInt(arrayOfByte.length);
      if (arrayOfByte.length > 0) {
        this.a.put(arrayOfByte);
      }
    }
    else
    {
      this.a.putInt(0);
    }
    this.a.flip();
    byte[] arrayOfByte = new byte[this.a.limit()];
    this.a.get(arrayOfByte);
    return arrayOfByte;
  }
  
  public boolean a(ByteBuf paramByteBuf)
  {
    int i = paramByteBuf.readableBytes();
    if (i < 8) {
      return false;
    }
    i -= 8;
    int j = paramByteBuf.readShort();
    byte[] arrayOfByte1;
    if (j > 0)
    {
      if (i < j) {
        return false;
      }
      i -= j;
      arrayOfByte1 = new byte[j];
      paramByteBuf.readBytes(arrayOfByte1);
      a(new String(arrayOfByte1, j));
    }
    j = paramByteBuf.readShort();
    if (j > 0)
    {
      if (i < j) {
        return false;
      }
      i -= j;
      arrayOfByte1 = new byte[j];
      paramByteBuf.readBytes(arrayOfByte1);
      b(new String(arrayOfByte1, j));
    }
    int k = paramByteBuf.readInt();
    byte[] arrayOfByte2;
    if (k > 0)
    {
      if (i < k) {
        return false;
      }
      i -= k;
      arrayOfByte2 = new byte[k];
      paramByteBuf.readBytes(arrayOfByte2);
      c(new String(arrayOfByte2, j));
    }
    if (i < 4) {
      return false;
    }
    k = paramByteBuf.readInt();
    i -= 4;
    if (k > 0)
    {
      if (i < k) {
        return false;
      }
      arrayOfByte2 = new byte[k];
      paramByteBuf.readBytes(arrayOfByte2);
      d(new String(arrayOfByte2, j));
    }
    return true;
  }
  
  public void d(String paramString)
  {
    this.e = paramString;
  }
  
  public String a(String paramString1, String paramString2)
  {
    if ((this.f == null) || (this.f.isEmpty())) {
      throw new RuntimeException("register client failed, vgroup is empty!");
    }
    StringBuilder localStringBuilder = new StringBuilder(this.e);
    String str1 = null;
    if (this.g == 1)
    {
      localStringBuilder.append("type").append('=').append("drds").append('\n');
    }
    else
    {
      if ((paramString1 == null) || (paramString1.isEmpty()) || (paramString2 == null) || (paramString2.isEmpty())) {
        return null;
      }
      String str2 = String.valueOf(System.currentTimeMillis());
      long l = o.a().b();
      try
      {
        Class localClass = Class.forName("com.taobao.spas.sdk.common.sign.SpasSigner");
        Method localMethod = localClass.getDeclaredMethod("sign", new Class[] { String.class, String.class });
        String str3;
        if (l == 2L)
        {
          if (StringUtils.isEmpty(this.h)) {
            str3 = this.f + ",127.0.0.1," + str2;
          } else {
            str3 = this.f + "," + this.h + "," + str2;
          }
        }
        else {
          str3 = this.f;
        }
        str1 = (String)localMethod.invoke(localClass, new Object[] { str3, paramString2 });
      }
      catch (ClassNotFoundException localClassNotFoundException)
      {
        throw new RuntimeException("digest failed, no dauth!");
      }
      catch (NoSuchMethodException localNoSuchMethodException)
      {
        throw new RuntimeException("digest failed, no dauth method!");
      }
      catch (InvocationTargetException localInvocationTargetException)
      {
        throw new RuntimeException("digest failed, invoke dauth method!");
      }
      catch (IllegalAccessException localIllegalAccessException)
      {
        throw new RuntimeException("digest failed, invoke dauth method!");
      }
      if ((str1 == null) || (str1.isEmpty())) {
        throw new RuntimeException("digest empty!");
      }
      localStringBuilder.append("ak").append('=').append(paramString1).append('\n');
      localStringBuilder.append("digest").append('=').append(str1).append('\n');
      if (l == 2L) {
        localStringBuilder.append("timestamp").append('=').append(str2).append('\n');
      }
    }
    this.e = localStringBuilder.toString();
    return str1;
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.a.b.c
 * JD-Core Version:    0.7.0.1
 */